package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goodsbean.goodsbo.CreateGoodsBO;
import com.cskaoyan.bean.goodsbean.goodsbo.DeleteGoodsBo;
import com.cskaoyan.bean.goodsbean.goodsbo.UpdateGoodsBO;
import com.cskaoyan.bean.goodsbean.goodsvo.CatAndBrandVO;
import com.cskaoyan.bean.goodsbean.goodsvo.GoodsDetailVO;
import com.cskaoyan.bean.goodsbean.goodsvo.GoodsListVO;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: whyccz-mall-project
 * @description:
 * @create: 2021-06-04 19:40
 **/

@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {
	@Autowired
	GoodsService goodsService;

	@RequestMapping("list")
	public BaseRespVo goodsList(String goodsSn, String name,Integer page, Integer limit, String sort, String order){
		GoodsListVO goodsListVO=goodsService.selectGoodsList(goodsSn,name,page, limit, sort, order);
		return BaseRespVo.ok(goodsListVO);
	}

	@RequestMapping("create")
	public BaseRespVo createGoods(@RequestBody CreateGoodsBO createGoodsBO){
		//TODO 参数校验

		//新增商品 新增规格 新增库存
		goodsService.createGoods(createGoodsBO);
		return BaseRespVo.ok();
	}

	@RequestMapping("detail")
	public BaseRespVo goodsDetail(Integer id){
		GoodsDetailVO goodsDetailVO=goodsService.getGoodsDetail(id);
		return BaseRespVo.ok(goodsDetailVO);
	}

	@RequestMapping("catAndBrand")
	public BaseRespVo goodsCatAndBrand(){
		CatAndBrandVO catAndBrandVO=goodsService.getCatAndBrand();
		return BaseRespVo.ok(catAndBrandVO);
	}

	@RequestMapping("update")
	public BaseRespVo updateGoods(@RequestBody UpdateGoodsBO updateGoodsBO){
		//TODO 校验
		goodsService.updateGoods(updateGoodsBO);
		return BaseRespVo.ok();
	}

	@RequestMapping("delete")
	public BaseRespVo deleteGoods(@RequestBody DeleteGoodsBo deleteGoodsBo){
		goodsService.deleteGoods(deleteGoodsBo);
		return BaseRespVo.ok();
	}


}
